function G = specdirect1d(N)
% Solve the Green's function of -u'' + (1+sin(x)) u  on [0,1] with
% periodic boundary condition with spectral method.
N = 32;
h = 1 / N;
xmesh = (0:N-1)'*h;
kvec = ((-N/2):(N/2-1))';
e = ones(N,1);
Ak = spdiags([1/2i*e,  (4*pi^2 * kvec.^2+1),  -1/2i*e], ...
  -1:1, N, N);
f = eye(N);
fk = fft(f,[],1)*h;
fk = fftshift(fk,1);
uk = Ak \ fk;
uk = fftshift(uk,1);
ux = ifft(uk,[],1)*N;
G = real(ux);
